﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using LantinxShare.LBS.Location;

namespace LantinxLBSTest
{
    class Program
    {
        //private const String url = "http://localhost:17307/AddressPage.aspx?option=setlocation&userid=1";
        // private const String url = "http://www.echotian.com/echo/addresspage.aspx?option=setaddress";

        //Getuser
      //private const String url = "http://localhost:17307/AddressPage.aspx?option=getuserbypwd";
        private static String url = "http://www.echotian.com/echo/AddressPage.aspx?option=getmark&random=" + DateTime.Now.Ticks;
        static void Main(string[] args)
        {
            CookieContainer cc = new CookieContainer();
            //string postData = "params=" + GetDefault();
            try
            {
                string postData ="" ;//"name=cx&pwd=1"
                byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化

                HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(new Uri(url));
                webRequest2.CookieContainer = cc;
                webRequest2.Method = "POST";
                webRequest2.ContentType = "application/x-www-form-urlencoded";
                webRequest2.ContentLength = byteArray.Length;
                Stream newStream = webRequest2.GetRequestStream();
                // Send the data.
                newStream.Write(byteArray, 0, byteArray.Length);    //写入参数
                newStream.Close();

                HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
                StreamReader sr2 = new StreamReader(response2.GetResponseStream(), Encoding.UTF8);
                string text2 = sr2.ReadToEnd();
                Console.WriteLine(text2);
                Console.ReadKey();
            }
            catch (Exception ex)
            {
            }


        }
        private static String GetDefault()
        {
            string result = GLocation.GetGLocationString(
                new List<GLocation>()
                {
                    new GLocation(){Title="a",Location=new GPoint(121.478759938092,31.2039347917019),GTimeStamp=CDateStampEx.ConvertToDateTime("201205231317"),Speed=5.0,Altitude=31.5},
                    new GLocation(){Title="b",Location=new GPoint(121.479759938092,31.2079347917019),GTimeStamp=CDateStampEx.ConvertToDateTime("201205231317"),Speed=5.0,Altitude=0},
                    new GLocation(){Title="c",Location=new GPoint(121.479739938092,31.2179347917019),GTimeStamp=CDateStampEx.ConvertToDateTime("201205231317"),Speed=5.0,Altitude=31.5},
                    new GLocation(){Title="d",Location=new GPoint(121.479759938092,31.2089348917019),GTimeStamp=CDateStampEx.ConvertToDateTime("201205231317"),Speed=5.0,Altitude=0},
                    new GLocation(){Title="e",Location=new GPoint(121.479759938092,31.2099347917019),GTimeStamp=CDateStampEx.ConvertToDateTime("201205231317"),Speed=5.0,Altitude=31.5},
                    new GLocation(){Title="h",Location=new GPoint(121.479759938092,31.2099347917019),GTimeStamp=CDateStampEx.ConvertToDateTime("201205281317"),Speed=5.0,Altitude=31.5},
                    new GLocation(){Title="i",Location=new GPoint(121.479759938092,31.2089348917019),GTimeStamp=CDateStampEx.ConvertToDateTime("201205281317"),Speed=5.0,Altitude=0},
                }
                );
            return result;
        }
    }
    public class CDateStampEx
    {
        public static DateTime ConvertToDateTime(string dateTime)
        {
            return new DateTime(
                                            int.Parse(dateTime.Substring(0, 4)),
                                            int.Parse(dateTime.Substring(4, 2)),
                                            int.Parse(dateTime.Substring(6, 2)),
                                            int.Parse(dateTime.Substring(8, 2)),
                                            int.Parse(dateTime.Substring(10, 2)), 0);
        }
        public static DateTime ConvertToDateTime(long dateTime)
        {
            return ConvertToDateTime(dateTime.ToString());
        }
    }
}
